package com.lvmama.task.common.utils;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by troy on 16/5/19.
 */
public class Constant {

    private static volatile Constant instance = null;
    private static Properties properties;

    private void init() {
        try {
            properties = new Properties();
            properties.load(getClass().getResourceAsStream("/const.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private Constant() {
        init();
    }

    public static Constant getInstance() {
        if (instance == null) {
            synchronized (Constant.class) {
                if (instance == null) {
                    instance = new Constant();
                }
            }
        }
        return instance;
    }

    public String getProperty(String key) {
        return getValue(key);
    }

    /**
     * 获取属性
     *
     * @return
     */
    public String getValue(String key) {
        return System.getProperty(key) != null ? System.getProperty(key) : properties.getProperty(key);
    }

    public enum TIME_CONSUMING_MILLIS {

        SECOND_1("1秒", 1000),
        SECOND_5("5秒", 5000),
        SECOND_10("10秒", 10000),
        SECOND_15("15秒", 15000),
        SECOND_30("30秒", 30000),
        MINUTE_1("1分钟", 60000),
        MINUTE_5("5分钟", 300000),
        MINUTE_10("10分钟", 600000),
        MINUTE_15("15分钟", 900000),
        MINUTE_30("30分钟", 1800000),
        HOURS_1("1小时", 3600000),
        HOURS_2("2小时", 7200000),
        HOURS_3("3小时", 10800000),
        HOURS_6("6小时", 21600000),
        HOURS_12("12小时", 43200000);

        private String cnName;
        private int millis;

        TIME_CONSUMING_MILLIS(String cnName, int millis) {
            this.cnName = cnName;
            this.millis = millis;
        }


        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

       /* public static String getCnName(String code) {
            for (TIME_CONSUMING_MILLIS item : TIME_CONSUMING_MILLIS.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }*/

        public int getMillis() {
            return this.millis;
        }

        @Override
        public String toString() {
            return this.name();
        }
    }

}
